package ltd.newbee.mall.dao;

import ltd.newbee.mall.entity.Role;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

@Mapper
public interface RoleMapper {

    List<Role> selectRoleList(Map<String, Object> params);

    Role selectRoleById(Long roleId);

    int insertRole(Role role);

    int updateRole(Role role);

    int deleteRole(Long roleId);

    int batchDeleteRole(Long[] roleIds);

    // 统计角色用户数量
    int countUsersByRoleId(Long roleId);

    // 检查角色名称是否重复
    int countByRoleName(@Param("roleName") String roleName, @Param("excludeRoleId") Long excludeRoleId);

    /**
     * 根据角色ID查询菜单ID列表
     */
    List<Long> selectMenuIdsByRoleId(@Param("roleId") Long roleId);

    /**
     * 删除角色菜单权限
     */
    int deleteRoleMenuByRoleId(@Param("roleId") Long roleId);

    /**
     * 批量插入角色菜单权限
     */
    int batchInsertRoleMenu(@Param("roleId") Long roleId, @Param("menuIds") List<Long> menuIds);

    /**
     * 根据用户ID查询角色名称
     */
    String selectRoleNameByUserId(@Param("userId") Long userId);

}
